﻿package component.tree.web.taglib;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

import component.tree.util.StringUtil;
import component.tree.web.action.TreeAction;
import component.tree.web.view.TreeView;

public class TreeTag extends BaseTag {
	
	private String componentId;
	private String title;
	private String treeView;
	private String condition;
	
	private String useBaseIconAble = "true";//是否使用标题图片
	private String useLinesAble = "true";//是否使用虚线连着
	private String useIconsAble = "true";//是否使用图片
	private String selectMoreAble = "false";//是否能够选择多个节点，如果是就用checkbox
	private String selectFolderAble = "true";//是否能够选择目录
	private String loadAllAble = "false";//是否一次性加载还是动态加载
	private String firstShowLevel = "1";//第一次显示几层
	
	private String targetAble = "false";//是否有链接
	private String searchAble = "false";
	private String url;
	private String target;
	private String context;
	
	private String refreshAble = "false";
	private String searchName;
	private String searchFlag;
	
	static TreeAction treeAction = new TreeAction();
	
	private boolean getBoolean(String booleanStr){
		return new Boolean(booleanStr).booleanValue();
	}
	private TreeView getTreeViewData(){
		HttpServletRequest request = (HttpServletRequest)this.getRequest();

		List treeList = null;
		boolean isSearchAble = false;
		if("true".equals(searchAble)) isSearchAble = true;
		if(loadAllAble.equals("true")){
			treeList = treeAction.getAllTreeData(this.componentId, condition, searchName, isSearchAble, request);
		}else{
			treeList = treeAction.getRootTreeData(componentId, condition, request);
		}
		//treeView.setTreeList(treeList);
		
		TreeView treeView = new TreeView(this.context,treeList);
		treeView.setTitle(this.getTitle());
		treeView.setUseBaseIcon(this.getBoolean(this.useBaseIconAble));
		treeView.setUseLines(this.getBoolean(this.useLinesAble));
		treeView.setUseIcons(this.getBoolean(this.useIconsAble));
		treeView.setSelectMore(this.getBoolean(this.selectMoreAble));
		treeView.setSelectFolder(this.getBoolean(this.selectFolderAble));
		treeView.setLoadAll(this.getBoolean(this.loadAllAble));
		treeView.setFirstShowLevel(new Integer(this.firstShowLevel).intValue());
		
		treeView.setTarget(this.getBoolean(this.targetAble));
		treeView.setTarget(this.target);
		if(!StringUtil.isNull(this.url)){
			treeView.setUrl(this.context + this.url);
		}
		//treeView.setSearch(this.getBoolean(this.searchAble));
		treeView.setSearch(this.getBoolean(this.searchFlag));
		treeView.setSearchName(searchName);
		
		treeView.setComponentId(this.componentId);
		treeView.setTreeObj(this.id);
		
		return treeView;
	}
	
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest)this.getRequest();
		HttpServletResponse response = this.getResponse();
		String context = this.getContext();
		this.context = context;

		this.setCache();
		
		TreeView treeView = this.getTreeViewData();
		
		this.print(treeView.toString());

		return super.doStartTag();

	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTreeView() {
		return treeView;
	}

	public void setTreeView(String treeView) {
		this.treeView = treeView;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public String getComponentId() {
		return componentId;
	}

	public void setComponentId(String componentId) {
		this.componentId = componentId;
	}

	public String getUseLinesAble() {
		return useLinesAble;
	}

	public void setUseLinesAble(String useLinesAble) {
		this.useLinesAble = useLinesAble;
	}

	public String getUseIconsAble() {
		return useIconsAble;
	}

	public void setUseIconsAble(String useIconsAble) {
		this.useIconsAble = useIconsAble;
	}

	public String getTargetAble() {
		return targetAble;
	}

	public void setTargetAble(String targetAble) {
		this.targetAble = targetAble;
	}

	public String getSelectMoreAble() {
		return selectMoreAble;
	}

	public void setSelectMoreAble(String selectMoreAble) {
		this.selectMoreAble = selectMoreAble;
	}

	public String getSelectFolderAble() {
		return selectFolderAble;
	}

	public void setSelectFolderAble(String selectFolderAble) {
		this.selectFolderAble = selectFolderAble;
	}

	public String getLoadAllAble() {
		return loadAllAble;
	}

	public void setLoadAllAble(String loadAllAble) {
		this.loadAllAble = loadAllAble;
	}

	public String getFirstShowLevel() {
		return firstShowLevel;
	}

	public void setFirstShowLevel(String firstShowLevel) {
		this.firstShowLevel = firstShowLevel;
	}

	public String getUseBaseIconAble() {
		return useBaseIconAble;
	}

	public void setUseBaseIconAble(String useBaseIconAble) {
		this.useBaseIconAble = useBaseIconAble;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getTarget() {
		return target;
	}
	public void setTarget(String target) {
		this.target = target;
	}
	public String getSearchAble() {
		return searchAble;
	}
	public void setSearchAble(String searchAble) {
		this.searchAble = searchAble;
	}
	public String getRefreshAble() {
		return refreshAble;
	}
	public void setRefreshAble(String refreshAble) {
		this.refreshAble = refreshAble;
	}
	public String getSearchName() {
		return searchName;
	}
	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}
	public String getSearchFlag() {
		return searchFlag;
	}
	public void setSearchFlag(String searchFlag) {
		this.searchFlag = searchFlag;
	}
	
	
}